﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    [CanEditMultipleObjects, CustomEditor(typeof(SkinnedMeshRenderer))]
    internal class SkinnedMeshRendererEditor : Editor
    {
        private SerializedProperty m_AABB;
        private BoxEditor m_BoxEditor = new BoxEditor(false, s_BoxHash);
        private SerializedProperty m_CastShadows;
        private SerializedProperty m_DirtyAABB;
        private SerializedProperty m_LightProbeAnchor;
        private SerializedProperty m_Materials;
        private SerializedProperty m_ReceiveShadows;
        private SerializedProperty m_UseLightProbes;
        private static int s_BoxHash = "SkinnedMeshRendererEditor".GetHashCode();

        public void OnDisable()
        {
            this.m_BoxEditor.OnDisable();
        }

        public void OnEnable()
        {
            this.m_CastShadows = base.serializedObject.FindProperty("m_CastShadows");
            this.m_ReceiveShadows = base.serializedObject.FindProperty("m_ReceiveShadows");
            this.m_Materials = base.serializedObject.FindProperty("m_Materials");
            this.m_UseLightProbes = base.serializedObject.FindProperty("m_UseLightProbes");
            this.m_LightProbeAnchor = base.serializedObject.FindProperty("m_LightProbeAnchor");
            this.m_AABB = base.serializedObject.FindProperty("m_AABB");
            this.m_DirtyAABB = base.serializedObject.FindProperty("m_DirtyAABB");
            this.m_BoxEditor.OnEnable();
            this.m_BoxEditor.SetAlwaysDisplayHandles(true);
        }

        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            EditorGUIUtility.LookLikeInspector();
            EditorGUILayout.PropertyField(this.m_CastShadows, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_ReceiveShadows, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Materials, true, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_UseLightProbes, new GUILayoutOption[0]);
            if (this.m_UseLightProbes.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(this.m_LightProbeAnchor, new GUIContent("Anchor Override", this.m_LightProbeAnchor.tooltip), new GUILayoutOption[0]);
                EditorGUI.indentLevel--;
            }
            string[] propertyToExclude = new string[] { "m_CastShadows", "m_ReceiveShadows", "m_Materials", "m_UseLightProbes", "m_LightProbeAnchor", "m_AABB" };
            Editor.DrawPropertiesExcluding(base.serializedObject, propertyToExclude);
            EditorGUIUtility.LookLikeControls();
            EditorGUI.indentLevel++;
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_AABB, new GUIContent("Bounds"), new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                this.m_DirtyAABB.boolValue = false;
            }
            EditorGUI.indentLevel--;
            base.serializedObject.ApplyModifiedProperties();
        }

        public void OnSceneGUI()
        {
            SkinnedMeshRenderer target = (SkinnedMeshRenderer) base.target;
            if (target.updateWhenOffscreen)
            {
                Bounds bounds = target.bounds;
                Vector3 center = bounds.center;
                Vector3 size = bounds.size;
                this.m_BoxEditor.DrawWireframeBox(center, size);
            }
            else
            {
                Undo.SetSnapshotTarget(target, "Modified SkinnedMeshRenderer Bounds");
                Bounds localBounds = target.localBounds;
                Vector3 vector3 = localBounds.center;
                Vector3 vector4 = localBounds.size;
                if (this.m_BoxEditor.OnSceneGUI(target.actualRootBone, Handles.s_BoundingBoxHandleColor, false, ref vector3, ref vector4))
                {
                    target.localBounds = new Bounds(vector3, vector4);
                }
            }
        }
    }
}

